function e(e, t) {
    if (!(e instanceof t)) throw new TypeError("Cannot call a class as a function");
}

Object.defineProperty(exports, "__esModule", {
    value: !0
});

var t = function() {
    function e(e, t) {
        for (var o = 0; o < t.length; o++) {
            var a = t[o];
            a.enumerable = a.enumerable || !1, a.configurable = !0, "value" in a && (a.writable = !0), 
            Object.defineProperty(e, a.key, a);
        }
    }
    return function(t, o, a) {
        return o && e(t.prototype, o), a && e(t, a), t;
    };
}(), o = function() {
    function o(t, a, n) {
        e(this, o), this.callback = a, "string" == typeof t && (t = [ t ]), this.downloadFiles(t);
    }
    return t(o, [ {
        key: "downloadFiles",
        value: function(e) {
            this.count = e.length, this.counter = 0, this.dl_fail = !1;
            var t = this;
            wxapp.tools.fileSystem.createFolders(e);
            var o = new wxapp.ClsLib.WxStopwatch(), a = new wxapp.Downloader();
            e.forEach(function(e) {
                var o = wxapp.objCenter.CreateObject2(t.callbackDonwFile, t);
                o.buildDownloadFile(e), a.downloadImageByUrl(o.url, o.name, o.success, o.fail, o.path);
            }), o.log("列表时间");
        }
    }, {
        key: "callbackDonwFile",
        value: function(e) {
            if (e.isSuccess() || (this.dl_fail = !0), this.counter++, wxapp.sw.log2(), this.counter >= this.count) if (this.dl_fail) this.callback(!1); else {
                return;
            }
        }
    } ]), o;
}();

exports.default = o;

var a = function() {
    function o(t, a, n) {
        e(this, o), n && (this.callbackProgress = n), a && (this.callbackFinish = a), this.path = t, 
        this.sw = new wxapp.ClsLib.WxStopwatch();
    }
    return t(o, [ {
        key: "startDownloadZip",
        value: function() {
            this.sw.start();
            var e = wxapp.objCenter.CreateObject2(this._cbFinish, this);
            e.buildDownloadFile(this.path), wx.downloadFile(e).onProgressUpdate(this._cbProgress.bind(this));
        }
    }, {
        key: "_cbFinish",
        value: function(e) {
            this.sw.log2("下载总时间");
            var t = {};
            if (t.ok = e.isSuccess(), t.statusCode = e.getResult().statusCode, 0 == t.ok) return console.error("下载失败"), 
            void this.callbackFinish(t);
            var o = this;
            wxapp.tools.unzipRes(e.getResult().tempFilePath, function(e) {
                t.ok = e, o.callbackFinish(t);
            });
        }
    }, {
        key: "_cbProgress",
        value: function(e) {
            this.callbackProgress && this.callbackProgress(e);
        }
    } ]), o;
}();

wxapp.tools.downloadFishRes = function(e, t) {
    new o(e, t);
}, wxapp.tools.downloadZip = function(e, t, o) {
    new a(e, t, o).startDownloadZip();
}, wxapp.tools.unzipRes = function(e, t) {
    var o = new wxapp.ClsLib.WxStopwatch(), a = wx.getFileSystemManager(), n = wxapp.objCenter.CreateObject2(function(e) {
        o.log("解压完毕"), e.isSuccess() ? e.error_text = "" : e.error_text = "wxapp.tools.unzipRes 解压缩失败", 
        t && t(e.isSuccess(), e.error_text);
    });
    n.zipFilePath = e, n.targetPath = wx.env.USER_DATA_PATH, a.unzip(n);
}, wxapp.tools.handleZip = function(e, t, o) {
    var a = function() {
        wxapp.model.loading.removeLocalInfo();
        var e = wxapp.tools.fileSystem.wxUserPath + "/res/";
        wxapp.tools.fileSystem.delFolder(e);
    }, n = function() {
        wxapp.tools.downloadZip(e, function(e) {
            if (e.ok) {
                try {
                    wx.setStorageSync(wxapp.Const.StorageKey.Version, wxapp.Const.vebVersion);
                } catch (e) {}
                a();
            }
            t(e);
        }, o);
    }, i = wxapp.objCenter.CreateObject2(function(e) {
        if (e.isSuccess()) {
            var o = wx.getFileSystemManager();
            try {
                var a = JSON.parse(o.readFileSync(e.getResult().tempFilePath, "utf8")).version;
                wxapp.Const.vebVersion = a;
            } catch (e) {
                return (s = {}).ok = !1, s.errStr = "下载version失败", void t(s);
            }
            try {
                var i = wx.getStorageSync(wxapp.Const.StorageKey.Version);
            } catch (e) {
                return void n();
            }
            if (i != a) n(); else {
                var s = {};
                s.ok = !0, t(s);
            }
        }
    });
    i.buildDownloadFile(wxapp.Const.versionPath), wx.downloadFile(i);
};